package com.rmondjone.view

import android.animation.ObjectAnimator
import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.view.ViewGroup
import android.view.animation.LinearInterpolator

/**
 * copyright：
 * @author：anthui creation date： .
 * @since: 1.0.0
 * @describe:
 */
class ScanningView(context: Context, attrs: AttributeSet?) : androidx.appcompat.widget.AppCompatImageView(context, attrs) {
    var animatior: ObjectAnimator? = null


    fun startAnimator() {

        if (animatior != null) {
            return
        }

        visibility = View.VISIBLE
        (parent as ViewGroup).post {
            val height = (parent as ViewGroup).measuredHeight - measuredHeight
            animatior = ObjectAnimator.ofFloat(this, "translationY", height.toFloat()).apply {
                //匀速滑动
                interpolator = LinearInterpolator()
                duration = 3000
                repeatCount = -1
                start()
            }
            //父控件的 高度，减去当前控件的高度，可就是移动的高度

        }
    }

    fun stopAnimator() {
        animatior?.cancel()
        animatior = null
        visibility = View.GONE
    }


}